// Creation History: 
//---------------------------------------------
// COMPANY : HTHK
// BY      : Zhiguo Yang
// Date    : 30/03/2005
// CRLOG   : P999
//---------------------------------------------
//
/*
 * Created on 2005-1-1
 * 
 * $Id: SchedulerListener.java,v 1.1.1.1 2013/08/16 05:35:48 tengyang Exp $
 * $Log: SchedulerListener.java,v $
 * Revision 1.1.1.1  2013/08/16 05:35:48  tengyang
 * no message
 *
 * Revision 1.3  2005/03/31 02:53:43  zhyan
 * Change the file header
 *
 * Revision 1.2  2005/03/30 13:30:30  zhyan
 * Add the file header
 *
 * Revision 1.1  2005/03/28 08:05:50  zhyan
 * Add common Job scheduler
 *
 * Revision 1.1  2005/01/17 09:18:45  zhyan
 * Add the ServletContextListener that handles job scheduler to system.
 *
 * 
 * Copyright Global Delivery China Center
 * Hewlett Packard Crop. 2005 All Rights Reserved
 */
package com.hp.gdcc.webframe.scheduler;

import java.io.File;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * This is a servlet context listener. 
 * It handles the starting and ending of the job scheduler.  
 * 
 * @author <a href="mailto:zhi-guo.yang@hp.com">Zhiguo Yang</a>
 * <p>
 * CopyRight HP GDCC 2004
 * </p>
 */
public class SchedulerListener implements ServletContextListener {
  
  /** The job scheduler object */
  private SimpleScheduler scheduler = null;
  
  /**
   * Shut down the job scheduler.
   * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
   */
  @Override
public void contextDestroyed(ServletContextEvent sce) {
    scheduler.shutdownScheudler();
  }
  
  /**
   * Initialize the job scheduler, using /WEB-INF/config/jobinfo.xml as the 
   * confiuration file.
   * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
   */
  @Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext sc = sce.getServletContext();
    String realPath = sc.getRealPath("/WEB-INF/config/jobinfo.xml");
    File confFile = new File(realPath); 
    scheduler = new SimpleScheduler(confFile);
    scheduler.startScheduler();
  }
}
